package com.jvyou.subject.common.entity;

import com.jvyou.subject.common.enums.ResultCodeEnum;
import lombok.Data;

/**
 * @author 橘柚
 * @since 2024/9/26 20:05
 */
@Data
public class Result<T> {

    private Boolean success;

    private Integer code;

    private String msg;

    private T data;

    public static <T> Result<T> ok(T data) {
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMsg(ResultCodeEnum.SUCCESS.getMsg());
        result.setData(data);
        return result;
    }

    public static <T> Result<T> ok() {
        return ok(null);
    }


    public static <T> Result<T> fail(String msg, T data) {
        Result<T> result = new Result<>();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(T data) {
        return fail(ResultCodeEnum.FAIL.getMsg(), data);
    }

    public static <T> Result<T> fail(String msg) {
        return fail(msg, null);
    }

    public static <T> Result<T> fail() {
        return fail(null);
    }
}
